/**
 * 
 */
package com.lmqb.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.lmqb.constant.Constant;
import com.lmqb.constant.Fileds;
import com.lmqb.page.PagerModel;

public class BaseController implements Fileds
{
	@InitBinder
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception
	{
		DateFormat df = new SimpleDateFormat(Constant.DATA_FORMAT);
		CustomDateEditor editor = new CustomDateEditor(df, false);
		binder.registerCustomEditor(Date.class, editor);

	}
	
	protected PagerModel<?> setIfEmpty(PagerModel<?> pagerModel)
	{
		int page = pagerModel.getPage();
		if (page == 0)
		{
			pagerModel.setPage(1);
		}
		return pagerModel;
	}
	
	protected PagerModel<?> setIfEndty(PagerModel<?> pagerModel){
		int page = pagerModel.getPage();
		int totalPage = pagerModel.getTotalPage();
		if(page>totalPage){
			pagerModel.setPage(totalPage);
			pagerModel.setTot("已经最后一页");
		}
		return pagerModel;
	}

}
